<template>
    <div>
        <Bread></Bread>
        <el-card>
            <!-- 搜索 -->
            <el-row>
                <el-col :span="10">
                    <el-input placeholder="请输入内容" v-model="query.query" class="input-with-select">
                        <el-button slot="append" icon="el-icon-search" @click="getOrderList"></el-button>
                    </el-input>
                </el-col>
            </el-row>
            <!-- 表格 -->
            <el-table :data="tableData" border style="width: 100%">
                <el-table-column type="index" label="#">
                </el-table-column>
                <el-table-column prop="order_id" label="订单编号">
                </el-table-column>
                <el-table-column prop="order_price" label="订单价格">
                </el-table-column>
                <el-table-column prop="is_send" label="是否付款">
                </el-table-column>
                <el-table-column prop="is_send" label="是否发货">
                </el-table-column>
                <el-table-column prop="create_time" label="下单时间">
                    <template slot-scope="scope">
                        {{ scope.row.create_time | dateFormate }}
                    </template>
                </el-table-column>
                <el-table-column prop="address" label="操作" width="200">
                    <template slot-scope="scope">
                        <el-button type="primary" icon="el-icon-edit" size="mini" @click="showCity(scope.row.order_id)">
                        </el-button>
                        <el-button type="success" icon="el-icon-share" size="mini"
                            @click="showWuLiu(scope.row.order_id)"></el-button>
                    </template>
                </el-table-column>
            </el-table>
            <!-- 修改地址对话框 -->
            <el-dialog title="修改地址" :visible.sync="dialogFormVisible" width="700px">
                <el-form :model="form">
                    <el-form-item label="省/市/区" label-width="80px">
                        <el-cascader v-model="value" :options="options" @change="handleChange"></el-cascader>
                    </el-form-item>
                    <el-form-item label="详细地址" label-width="80px">
                        <el-input v-model="form.cityValue" autocomplete="off"></el-input>
                    </el-form-item>
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button @click="dialogFormVisible = false">取 消</el-button>
                    <el-button type="primary" @click="dialogFormVisible = false">确 定</el-button>
                </div>
            </el-dialog>
            <!-- 物流信息对话框 -->
            <el-dialog title="物流进度" :visible.sync="cityDialog" width="300px">
                <el-timeline :reverse="reverse">
                    <el-timeline-item v-for="(activity, index) in activities" :key="index" :timestamp="activity.time">
                        {{ activity.context }}
                    </el-timeline-item>
                </el-timeline>
            </el-dialog>
            <!-- 分页 -->
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                :current-page="query.pagenum" :page-sizes="[3, 4, 5, 6]" :page-size="query.pagesize"
                layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </el-card>
    </div>
</template>

<script>
import mixin from "@/mixin/mixin"
import { orderList } from "@/utils/orders/orderList.js"
import orderCity from "@/utils/orders/orderCity.js"
export default {
    mixins: [mixin],
    data() {
        return {
            tableData: [],//订单列表数据
            query: {
                query: '',
                pagenum: 1,
                pagesize: 5,
            },
            cityID: 0,//修改地址||物流信息id
            dialogFormVisible: false,
            form: {
                cityValue: '',
            },
            value: [],
            options: [
                {
                    value: 'zhinan',
                    label: '北京',
                    children: [{
                        value: 'shejiyuanze',
                        label: '海淀',
                        children: [{
                            value: 'yizhi',
                            label: '白水哇'
                        },
                        ]
                    }],
                },
                {
                    value: 'zhinan',
                    label: '河北',
                    children: [{
                        value: 'shejiyuanze',
                        label: '石家庄',
                        children: [{
                            value: 'yizhi',
                            label: '不知道'
                        },
                        ]
                    }],
                },
                {
                    value: 'zhinan',
                    label: '陕西',
                    children: [{
                        value: 'shejiyuanze',
                        label: '西安',
                        children: [{
                            value: 'yizhi',
                            label: '长安'
                        },
                        ]
                    }],
                },
            ],
            cityDialog: false,
            /* 物流进度 */
            reverse: true,
            activities: [

            ],
            total:0,
        }
    },
    methods: {
        /* 获取订单列表数据 */
        async getOrderList() {
            let res = await orderList(this.query);
            // console.log(res);
            /* 对订单列表数据里的时间进行转换 */
            // res.data.goods.forEach((item) => {
            //     item.update_time = this.getNewTime(item.update_time);
            // })
            // console.log(res);
            this.tableData = res.data.goods;
            this.total = res.data.total;
        },
        /* 地址对话框显示 */
        showCity(id) {
            // console.log(id);
            this.dialogFormVisible = true;
        },
        /* 修改地址 */
        async changeCity() {
            let res = await orderCity(this.cityID);
        },
        /* 级联选择器change事件 */
        handleChange(value) {
            // console.log(value);
        },
        /* 显示查看物流信息对话框 */
        async showWuLiu(id) {
            this.cityDialog = true;
            let res = await orderCity(this.cityID);
            res.data.forEach((item) => {
                this.activities.push(item);
            })
        },
        /* 封装一个处理日期格式的函数 */
        getNewTime(str) {
            /* 转换年 */
            let year = str.getFullYear();
            /* 转换月 */
            let month = str.getMonth() + 1;
            month < 10 ? '0' + month : month;
            /* 转换天 */
            let day = str.getDate();
            day < 10 ? '0' + day : day;
            return year + '-' + month + '-' + day;
        },
        /* 当前页发生改变触发 */
        handleCurrentChange(num) {
            console.log(num);
            this.query.pagenum = num;
            this.getOrderList();
        },
        /* 每页条数发生变化触发 */
        handleSizeChange(size) {
            console.log(size);
            this.query.pagesize = size;
            this.getOrderList();
        }
    },
    mounted() {
        this.getOrderList();
    },
}
</script>

<style lang="scss" scoped>

</style>